package com.lianzhihui.romeex.widget.dialog;

import android.content.Context;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chaychan.library.UIUtils;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.inter.SetListener;
import com.lianzhihui.romeex.ui.base.BaseDialog;
import com.lianzhihui.romeex.utils.TextUtil;
import com.lianzhihui.romeex.utils.UiUtils;

import butterknife.BindColor;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * Description: 一个设置dialog
 * Author: RAMON
 * CreateDate: 2020/11/6 3:29 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class SetEtDialog extends BaseDialog {

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.et_set)
    EditText et_set;
    @BindView(R.id.bt_submit)
    Button bt_submit;

    SetListener listener;

    public SetEtDialog(@NonNull Context context) {
        super(context);
    }

    public void setListener(SetListener listener) {
        this.listener = listener;
    }

    public EditText getEt() {
        return et_set;
    }

    public void setTexts(String title, String hint, String btText) {
        if (!TextUtils.isEmpty(title)) {
            tv_title.setText(title);
        }
        if (!TextUtils.isEmpty(hint)) {
            et_set.setHint(hint);
        }
        if (!TextUtils.isEmpty(btText)) {
            bt_submit.setText(btText);
        }
    }

    @Override
    protected int provideViewId() {
        return R.layout.dialog_set_et_layout;
    }

    @Override
    protected void initView() {
        setB2T();
        UiUtils.setEditText8(et_set);
    }

    @OnClick({R.id.bt_submit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_submit:
                try {
                    double num = Double.parseDouble(et_set.getText().toString());
                    listener.getInput(num);
                }catch(Exception e){
                    listener.getInput(0D);
                }
                break;
        }
    }

}
